// 省市区联动逻辑
provinceSelect.addEventListener('change', function() {
    const citySelect = document.getElementById('city');
    const districtSelect = document.getElementById('district');
    
    // 清空市和区的下拉框
    citySelect.innerHTML = '<option value="">请选择市</option>';
    districtSelect.innerHTML = '<option value="">请选择区</option>';
    
    const selectedProvince = this.value;
    if (selectedProvince) {
        const cities = addressData["省"][selectedProvince];
        for (let city in cities) {
            const option = document.createElement('option');
            option.value = city;
            option.textContent = city;
            citySelect.appendChild(option);
        }
    }
});

// 使用jQuery实现区的联动
$('#city').change(function() {
    const selectedCity = $(this).val();
    const selectedProvince = $('#province').val();
    const districtSelect = $('#district');
    
    // 清空区的下拉框
    districtSelect.empty().append('<option value="">请选择区</option>');
    
    if (selectedCity) {
        const districts = addressData["省"][selectedProvince][selectedCity];
        districts.forEach(district => {
            districtSelect.append(`<option value="${district}">${district}</option>`);
        });
    }
});

// 表单提交事件
document.getElementById('registrationForm').addEventListener('submit', function(event) {
    event.preventDefault(); // 阻止默认提交行为

    const password = document.getElementById('password').value;
    const confirmPassword = document.getElementById('confirmPassword').value;
    const errorMessage = document.getElementById('error-message');

    // 检查密码是否匹配
    if (password !== confirmPassword) {
        errorMessage.textContent = "密码和确认密码不匹配！";
        return;
    }

    // 如果所有验证通过，清空错误信息并提交表单
    errorMessage.textContent = "";
    alert("注册成功！"); // 这里可以替换为实际的提交逻辑
    this.reset(); // 重置表单
});
